package com.trepadora.utils;

import java.util.EventObject;
import java.util.HashMap;

import org.ajax4jsf.event.PushEventListener;

/**
 * 
 * @author Karol Lotkowski
 * 
 */
public class ListenerManager {

	private HashMap<String,PushEventListener> listenerMap;
	
	private static final ListenerManager listenerInstance = new ListenerManager();
	
	private ListenerManager(){		
		this.listenerMap = new HashMap<String,PushEventListener>();
	}
	
	public static ListenerManager getInstance() {
		return listenerInstance;
	}

	public void addListenerToMap(String userId, PushEventListener listener){
		
		this.listenerMap.put(userId, listener);
	}
	
	public PushEventListener getListenerByUserId(String userId){
		
		return this.listenerMap.get(userId);
	}
	
	public boolean activeListenerByUserId(String userId) {
		
		((PushEventListener)this.listenerMap.get(userId)).onEvent(new EventObject(this)); 
		return true;
	}
	
	public HashMap<String,PushEventListener> getListnerMap(){
		return this.listenerMap;
	}
	
}
